
#include <transformationeditdialog.h>
#include <QGridLayout>


TransformationEditDialog::TransformationEditDialog(QWidget *parent)
  : QDialog(parent)
  , _gui (this)
{
  QGridLayout* layout = new QGridLayout(this);
  layout->addWidget(&_gui, 0, 0, 1, 1);


  QGridLayout* buttonLayout = new QGridLayout();
  buttonLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::MinimumExpanding, QSizePolicy::Minimum), 0, 0, 1, 1);

  _buttonOk = new QPushButton (tr("Ok"), this);
  _buttonReset = new QPushButton (tr("Reset"), this);
  _buttonCancel = new QPushButton (tr("Cancel"), this);
  buttonLayout->addWidget(_buttonReset,   0, 1, 1, 1);
  buttonLayout->addWidget(_buttonCancel,  0, 2, 1, 1);
  buttonLayout->addWidget(_buttonOk,      0, 3, 1, 1);
  layout->addLayout(buttonLayout,         1, 0, 1, 1);

  connect (_buttonOk, SIGNAL(clicked ()), this, SLOT(on_buttonOk_clicked ()));
  connect (_buttonCancel, SIGNAL(clicked()), this, SLOT(on_buttonCancel_clicked ()));
  connect (_buttonReset, SIGNAL(clicked ()), this, SLOT(on_buttonReset_clicked ()));
  connect (&_gui, SIGNAL(TransformationChanged()), this, SIGNAL(TransformationChanged ()));
}


void TransformationEditDialog::UpdateGUI ()
{
  _gui.UpdateGUI();
}

void TransformationEditDialog::on_buttonOk_clicked ()
{
  _gui.Apply();
  emit TransformationChanged ();
  setVisible(false);
}

void TransformationEditDialog::on_buttonCancel_clicked ()
{
  _gui.Reset();
  emit TransformationChanged ();
  setVisible(false);
}


void TransformationEditDialog::on_buttonReset_clicked ()
{
  _gui.Reset();
  emit TransformationChanged ();
}

void TransformationEditDialog::SetTransformer (ceTransformer* transformer)
{
  _gui.SetTransformer(transformer);
}


TransformationEditDialog* TransformationEditDialog::Show(QWidget *parent)
{
  TransformationEditDialog* dlg = new TransformationEditDialog (parent);
  dlg->setVisible(true);
  dlg->setModal(false);

  return dlg;
}
